<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    use HasFactory;
    protected $fillable = ['user_id','order_no','address_id','amount','status','trade_no','pay_time','pay_type'];
    /**
     * 订单所属用户
     */
    public function user()
    {
        return $this->belongsTo(User::class,'user_id','id');
    }

    /**
     * 订单拥有的订单细节
     */
    public function orderDetails()
    {
        return $this->hasMany(OrderDetails::class,'order_id','id');
    }

    /**
     * 远程一对多
     */
    public function goods()
    {
        return $this->hasManyThrough(Good::class,orderDetails::class,'order_id','id','id','goods_id');
    }
}
